package com.swu.education.controller;

import com.swu.education.entity.Activity;
import com.swu.education.entity.Assignment;
import com.swu.education.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by nana on 2018/3/18.
 */
@RestController
public class ActivityController {
  @Autowired
  ActivityService activityService;

  //根据assignmentId查询当前的activity的相关信息
  @RequestMapping(value = "/getActivityById")
  public Activity getActivityById(@RequestParam(value = "activityId") int activityId){
    return activityService.getSingleActivityById(activityId);
  }


  //根据课程id 查询当前课程下的所有activity
  @RequestMapping(value = "/getAllActivity")
  public List<Activity> getAllActivity(HttpServletRequest request) throws Exception {
    int assignmentId = Integer.parseInt(request.getParameter("assignmentId"));
    return activityService.getActivityListByAssignmentId(assignmentId);
  }

  //创建activity
  @RequestMapping(value = "/createActivity")
  public Activity createActivity(HttpServletRequest request){
    int assignmentId = Integer.parseInt(request.getParameter("assignmentId"));
    String activityName = request.getParameter("activityName");
    String type = request.getParameter("type");
    String description = request.getParameter("description");
    String startTime = request.getParameter("startTime");
    String endTime = request.getParameter("endTime");
    return activityService.createActivityByAssignmentId(assignmentId,activityName,type,
            description,startTime,endTime);
  }

  //删除activity
  @RequestMapping(value = "/deleteActivity")
  public void deleteActivity(@RequestParam(value = "activityId") int activityId){
    activityService.deleteActivityIdById(activityId);
  }

  //修改activity信息
  @RequestMapping(value = "/modifyActivity")
  public void modifyActivity(HttpServletRequest request){
    int activityId = Integer.parseInt(request.getParameter("activityId"));
    String activityName = request.getParameter("activityName");
    String type = request.getParameter("type");
    String description = request.getParameter("description");
    String startTime = request.getParameter("startTime");
    String endTime = request.getParameter("endTime");
    activityService.modifyActivityInfoById(activityId,activityName,type,
            description,startTime,endTime);
  }
}
